<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title></title>
		<script type="text/javascript" src="../../js/boot.js"></script>
	</head>

	<body>
		<div style="width:99%;height:99%;">
			<div style="float:left; width:50%; height:100%;">
				<fieldset style="width: 100%;height:100%;">
					<legend><span>工时分项</span></legend>
					<div class="mini-fit">
						<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
							<a class="mini-button" plain="true" onclick="openAddSort()">新增</a>
							<a class="mini-button" plain="true" onclick="openModSort()">修改</a>
							<a class="mini-button" plain="true" onclick="doDelSort()">删除</a>
						</div>
						<ul id="sortTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="sortName" idField="projectSortID" resultAsTree="false">
						</ul>
					</div>
				</fieldset>
			</div>
			<div style="float:left; width:50%; height:100%;">
				<fieldset style="width: 100%;height:100%;">
					<legend><span>项目工作包</span></legend>
					<div class="mini-fit">
						<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
							<a class="mini-button" plain="true" onclick="openAddPacket()">新增</a>
							<a class="mini-button" plain="true" onclick="openModPacket()">修改</a>
							<a class="mini-button" plain="true" onclick="doDelPacket()">删除</a>
						</div>
						<ul id="packetTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="packetName" idField="projectPacketID" resultAsTree="false">
						</ul>
					</div>
				</fieldset>
			</div>
		</div>

		<div id="sortWin" class="mini-window" title="" style="width:300px;height:200px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div id="sortForm" style="padding:10px;">
				<input name="type" class="mini-hidden" value="update">
				<table align="center">
					<tr>
						<td align="right">工时分项编号：</td>
						<td align="left"><input id="projectSortID" name="projectSortID" class="mini-textbox"></td>
					</tr>
					<tr>
						<td align="right">工时分项名称：</td>
						<td align="left"><input id="sortName" name="sortName" class="mini-textbox"></td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" onClick="doSaveSort()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel(1)">取消</a>
			</div>
		</div>

		<div id="packetWin" class="mini-window" title="" style="width:300px;height:200px;" showMaxButton="true" showCollapseButton="true" showShadow="true" showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
			<div id="packetForm" style="padding:10px;">
				<input name="type" class="mini-hidden" value="update">
				<table align="center">
					<tr>
						<td align="right">工作包编号：</td>
						<td align="left"><input id="projectPacketID" name="projectPacketID" class="mini-textbox"></td>
					</tr>
					<tr>
						<td align="right">工作包名称：</td>
						<td align="left"><input id="packetName" name="packetName" class="mini-textbox"></td>
					</tr>
				</table>
			</div>
			<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
				<a class="mini-button" iconCls="icon-save" onClick="doSavePacket()">保存</a>
				<a class="mini-button" iconCls="icon-cancel" onClick="cancel(2)">取消</a>
			</div>
		</div>

	</body>

	<script type="text/javascript">
		miniInit();

		// 加载浅蓝色背景和去除滚动条
		$('.mini-splitter').addClass('bg');

		var sortTree = mini.get("sortTree");
		var sortWin = mini.get("sortWin");
		var sortForm = new mini.Form("#sortForm");
		http.get("/oa/project/sort/list.do", function(page) {
			if(page.data.length > 0) {
				sortTree.loadList(page.data, "projectSortID", "parentID");
			} else {
				sortTree.addNode({
					projectSortID: "ROOT",
					sortName: "公司"
				}, 0, null);
			}
		});

		function openAddSort() {
			var node = sortTree.getSelectedNode();
			if(node) {
				var uid = mini.prompt("请输入名称：", "请输入",
					function(action, value) {
						if(action == "ok") {
							// alert(value);
							debugger
							var all = sortTree.getChildNodes(node);
							var index = all.length;
							var id = "000" + (index + 1);
							var len = id.length;
							id = id.substr(len - 4, len);
							var data = {
								projectSortID: node.projectSortID + id,
								sortName: value,
								parentID: node.projectSortID,
								type: 'insert'
							}
							http.post("/oa/project/sort/save.do", data, function(page) {
								sortTree.addNode(data, index, node);
							});
						}
					}
				);
			} else {
				miniui.showWarnMessageBox("请先选择父组织！");
			}
		}

		function openModSort() {
			var node = sortTree.getSelectedNode();
			if(node) {
				sortForm.setData(node);
				sortWin.setTitle("修改");
				sortWin.showAtPos('center', 'middle');
			} else {
				miniui.showWarnMessageBox("请先选择要修改的组织！");
			}
		}

		function doSaveSort() {
			var node = sortTree.getSelectedNode();
			var data = sortForm.getData();
			http.post("/oa/project/sort/save.do", data, function(page) {
				sortWin.hide();
				sortTree.updateNode(node, data);
			});
		}

		function doDelSort() {
			var node = sortTree.getSelectedNode();
			if(node) {
				mini.confirm("确认删除该组织吗？", "删除操作", function(e) {
					if(e == "ok") {
						var data = {
							projectSortID: node.projectSortID
						};
						http.post("/oa/project/sort/delete.do", data, function(page) {
							sortTree.removeNode(node);
						});
					}
				});
			} else {
				miniui.showWarnMessageBox("请先选择要删除的组织！");
			}
		}

		var packetTree = mini.get("packetTree");
		var packetWin = mini.get("packetWin");
		var packetForm = new mini.Form("#packetForm");
		http.get("/oa/project/packet/list.do", function(page) {
			if(page.data.length > 0) {
				packetTree.loadList(page.data, "projectPacketID", "parentID");
			} else {
				packetTree.addNode({
					projectPacketID: "ROOT",
					packetName: "公司"
				}, 0, null);
			}
		});

		function openAddPacket() {
			var node = packetTree.getSelectedNode();
			if(node) {
				var uid = mini.prompt("请输入名称：", "请输入",
					function(action, value) {
						if(action == "ok") {
							// alert(value);
							debugger
							var all = packetTree.getChildNodes(node);
							var index = all.length;
							var id = "000" + (index + 1);
							var len = id.length;
							id = id.substr(len - 4, len);
							var data = {
								projectPacketID: node.projectPacketID + id,
								packetName: value,
								parentID: node.projectPacketID,
								type: 'insert'
							}
							http.post("/oa/project/packet/save.do", data, function(page) {
								packetTree.addNode(data, index, node);
							});
						}
					}
				);
			} else {
				miniui.showWarnMessageBox("请先选择父组织！");
			}
		}

		function openModPacket() {
			var node = packetTree.getSelectedNode();
			if(node) {
				packetForm.setData(node);
				packetWin.setTitle("修改");
				packetWin.showAtPos('center', 'middle');
			} else {
				miniui.showWarnMessageBox("请先选择要修改的组织！");
			}
		}

		function doSavePacket() {
			var node = packetTree.getSelectedNode();
			var data = packetForm.getData();
			http.post("/oa/project/packet/save.do", data, function(page) {
				packetWin.hide();
				packetTree.updateNode(node, data);
			});
		}

		function doDelPacket() {
			var node = packetTree.getSelectedNode();
			if(node) {
				mini.confirm("确认删除该组织吗？", "删除操作", function(e) {
					if(e == "ok") {
						var data = {
							projectPacketID: node.projectPacketID
						};
						http.post("/oa/project/packet/delete.do", data, function(page) {
							packetTree.removeNode(node);
						});
					}
				});
			} else {
				miniui.showWarnMessageBox("请先选择要删除的组织！");
			}
		}

		function cancel(index) {
			if(index == 1) {
				sortWin.hide();
			} else {
				packetWin.hide();
			}
		}
	</script>

</html>